home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / sgml / msdos / sgml07 / sgmlxtrn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-27  |  11.3 KB  |  222 lines

  1. /*    Standard Generalized Markup Language Users' Group (SGMLUG)
  2.                  SGML Parser Materials (ARCSGML 1.0)
  3.  
  4. (C) 1983-1988 Charles F. Goldfarb (assigned to IBM Corporation)
  5. (C) 1988-1991 IBM Corporation
  6.  
  7. Licensed to the SGML Users' Group for distribution under the terms of
  8. the following license:                                                       */
  9.  
  10. char license[] =
  11. "SGMLUG hereby grants to any user: (1) an irrevocable royalty-free,\n\
  12. worldwide, non-exclusive license to use, execute, reproduce, display,\n\
  13. perform and distribute copies of, and to prepare derivative works\n\
  14. based upon these materials; and (2) the right to authorize others to\n\
  15. do any of the foregoing.\n";
  16.  
  17. #include "sgmlincl.h"
  18.  
  19. /* SGMLXTRN: Storage allocation and initialization for all public variables.
  20.              Exceptions: Constants lex????? and del????? are defined in
  21.              LEX?????.C modules; constants pcb????? are defined in PCB?????.c.
  22. */
  23. int badresw = 0;              /* 1=REF_ out of context; 0=valid. */
  24. int charmode = 0;             /* >0=in #CHARS; 0=not. */
  25. int conactsw = 0;             /* 1=return saved content action 0=get new one.*/
  26. int conrefsw = 0;             /* 1=content reference att specified; 0=no. */
  27. int contersv = 0;             /* Save contersw while processing pending REF. */
  28. int contersw = 0;             /* 1=element or #CHARS out of context; 0=valid. */
  29. int datarc = 0;               /* Return code for data: DAF_ or REF_. */
  30. int delmscsw = 0;             /* 1=DELMSC must be read on return to es==0. */
  31. int didreq = 0;               /* 1=required implied tag processed; 0=no. */
  32. int dostag = 0;               /* 1=retry newetd instead of parsing; 0=parse. */
  33. int dtdsw = 0;                /* DOCTYPE declaration found: 1=yes; 0=no. */
  34. int entdatsw = 0;             /* 2=CDATA entity; 4=SDATA; 8=NDATA; 0=none. */
  35. int entpisw = 0;              /* 4=PI entity occurred; 0=not. */
  36. int eodsw = 0;                /* 1=eod found in error; 0=not yet. */
  37. int eofsw = 0;                /* 1=eof found in body of document; 0=not yet. */
  38. int es = -1;                  /* Index of current source in stack. */
  39. int etagimct = 0;             /* Implicitly ended elements left on stack. */
  40. int etagimsw = 0;             /* 1=end-tag implied by other end-tag; 0=not. */
  41. int etagmin = MINNONE;        /* Minim: NONE NULL NET DATA; implied by S/ETAG*/
  42. int etictr = 0;               /* Number of "NET enabled" tags on stack. */
  43. int etisw = 0;                /* 1=tag ended with eti; 0=did not. */
  44. int indtdsw = 0;              /* Are we in the DTD? 1=yes; 0=no. */
  45. int mslevel = 0;              /* Nesting level of marked sections. */
  46. int msplevel = 0;             /* Nested MS levels subject to special parse. */
  47. int prologsw = 1;             /* 1=in prolog; 0=not. */
  48. int pss = 0;                  /* SGMLACT: scbsgml stack level. */
  49. int sgmlsw = 0;               /* SGML declaration found: 1=yes; 0=no. */
  50. int stagmin = MINNONE;        /* Minimization: NONE, NULL tag, implied by STAG*/
  51. int tagctr = 0;               /* Tag source chars read. */
  52. int ts = -1;                  /* Index of current tag in stack. */
  53. struct parse *propcb = &pcbpro; /* Current PCB for prolog parse. */
  54. int aentctr = 0;              /* Number of ENTITY tokens in this att list. */
  55. int conact = 0;               /* Return code from content parse. */
  56. int conrefsv = 0;             /* Save conrefsw when doing implied start-tag.*/
  57. int dtdrefsw = 0;             /* External DTD? 1=yes; 0=no. */
  58. int etiswsv = 0;              /* Save etisw when processing implied start-tag.*/
  59. int grplvl = 0;               /* Current level of nested grps in model. */
  60. int idrctr = 0;               /* Number of IDREF tokens in this att list. */
  61. int mdessv = 0;               /* ES level at start of markup declaration. */
  62. int notadn = 0;               /* Position of NOTATION attribute in list. */
  63. int parmno = 0;               /* Current markup declaration parameter number. */
  64. int pexsw = 0;                /* 1=tag valid solely because of plus exception.*/
  65. int rcessv = 0;               /* ES level at start of RCDATA content. */
  66. int tagdelsw = 0;             /* 1=tag ended with delimiter; 0=no delimiter. */
  67. int tokencnt = 0;             /* Number of tokens found in attribute value. */
  68. struct entity *ecbdeflt = 0;  /* #DEFAULT ecb (NULL if no default entity). */
  69. struct etd *docetd = 0;       /* The etd for the document as a whole. */
  70. struct etd *etagreal = 0;     /* Actual or dummy etd that implied this tag. */
  71. struct etd *newetd = 0;       /* The etd for a start- or end-tag recognized. */
  72. struct etd *nextetd = 0;      /* ETD that must come next (only one choice). */
  73. struct etd *stagreal = 0;     /* Actual or dummy etd that implied this tag. */
  74. struct parse *conpcb = 0;     /* Current PCB for content parse. */
  75. UNCH *data = 0;               /* Pointer to returned data in buffer. */
  76. UNCH *mdname = 0;             /* Name of current markup declaration. */
  77. UNCH *ptcon = 0;              /* Current pointer into tbuf. */
  78. UNCH *ptpro = 0;              /* Current pointer into tbuf. */
  79. UNCH *rbufs = 0;              /* DOS file read area: start position for read. */
  80. UNCH *subdcl = 0;             /* Subject of markup declaration (e.g., GI). */
  81. UNCH Tstart = 0;              /* Save starting token for AND group testing. */
  82. UNS conradn = 0;              /* 1=CONREF attribute in list (0=no). */
  83. UNS datalen = 0;              /* Length of returned data in buffer. */
  84. UNS entlen = 0;               /* Length of TAG or EXTERNAL entity text. */
  85. UNS idadn = 0;                /* Number of ID attribute (0 if none). */
  86. UNS noteadn = 0;              /* Number of NOTATION attribute (0 if none). */
  87. UNS reqadn = 0;               /* Num of atts with REQUIRED default (0=none). */
  88. int grplongs;              /* Number of longs for GRPCNT bitvector. */
  89.  
  90. /* Variable arrays and structures.
  91. */
  92. struct ad *al = 0;            /* Current attribute list work area. */
  93. struct dcncb *dcntab[1];      /* List of data content notation names. */
  94. struct entity *etab[ENTHASH]; /* Entity hash table. */
  95. struct etd *etdtab[ETDHASH];  /* Element type definition hash table. */
  96. struct fpi fpidf;             /* Fpi for #DEFAULT entity. */
  97. struct id *itab[IDHASH];      /* Unique identifier hash table. */
  98. struct etd **nmgrp = 0;          /* Element name group */
  99. PDCB *nnmgrp = 0;          /* Notation name group */
  100. struct restate *scbsgml = 0;  /* SGMLACT: return action state stack. */
  101. struct source *scbs = 0;      /* Stack of open sources ("SCB stack"). */
  102. struct srh *srhtab[1];        /* List of SHORTREF table headers. */
  103. struct sgmlstat ds;           /* Document statistics. */
  104. struct switches sw;           /* Parser control switches set by text proc. */
  105. struct tag *tags = 0;         /* Stack of open elements ("tag stack"). */
  106. struct thdr *gbuf = 0;        /* Buffer for creating group. */
  107. struct thdr prcon[3];         /* 0-2: Model for *DOC content. */
  108. struct thdr undechdr;         /* 0:Default model hdr for undeclared content.*/
  109. UNCH *dtype = 0;              /* Document type name. */
  110. UNCH *entbuf = 0;             /* Buffer for entity reference name. */
  111. UNCH fce[2];                  /* String form of FCE char.
  112.                                  (fce[1] must be EOS).*/
  113. UNCH nonchbuf[2];             /* Buffer for non-SGML character reference.*/
  114. UNCH *tbuf;              /* Work area for tokenization. */
  115. UNCH *lbuf = 0;              /* In tbuf: Literal parse area.*/
  116. UNCH *sysibuf = 0;          /* Buffer for system identifiers. */
  117. UNCH *pubibuf = 0;          /* Buffer for public identifiers. */
  118. UNCH *nmbuf = 0;          /* Name buffer used by mdentity. */
  119. struct mpos *savedpos;
  120.  
  121. /* Constants.
  122. */
  123. struct map dctab[] = {        /* Keywords for declared content parameter.*/
  124.      key[KRCDATA],  MRCDATA+MPHRASE,
  125.      key[KCDATA],   MCDATA+MPHRASE,
  126.      key[KANY],     MANY+MCHARS+MGI,
  127.      key[KEMPTY],   MNONE+MPHRASE,
  128.      NULL,          0
  129. };
  130. struct map deftab[] = {       /* Default value keywords. */
  131.      key[KIMPLIED],  DNULL ,
  132.      key[KREQUIRED], DREQ  ,
  133.      key[KCURRENT],  DCURR ,
  134.      key[KCONREF],   DCONR ,
  135.      key[KFIXED],    DFIXED,
  136.      NULL,           0
  137. };
  138. struct map dvtab[] = {        /* Declared value: keywords and type codes.*/
  139. /*                                TYPE      NUMBER   */
  140. /*   grp             ANMTGRP      Case 1 0  Grp size */
  141. /*   grp member      ANMTGRP      Case   0  Position */
  142. /*   grp             ANOTEGRP     Case 1 1  Grp size */
  143.      key[KNOTATION], ANOTEGRP, /* Case   1  Position */
  144.      key[KCDATA],    ACHARS  , /* Case   2  Always 0 */
  145.      key[KENTITY],   AENTITY , /* Case   3  Normal 1 */
  146.      key[KID],       AID     , /* Case   4  Normal 1 */
  147.      key[KIDREF],    AIDREF  , /* Case   5  Normal 1 */
  148.      key[KNAME],     ANAME   , /* Case   6  Normal 1 */
  149.      key[KNMTOKEN],  ANMTOKE , /* Case   7  Normal 1 */
  150.      key[KNUMBER],   ANUMBER , /* Case   8  Normal 1 */
  151.      key[KNUTOKEN],  ANUTOKE , /* Case   9  Normal 1 */
  152.      key[KENTITIES], AENTITYS, /* Case   A  Normal 1 */
  153.      key[KIDREFS],   AIDREFS , /* Case   B  # tokens */
  154.      key[KNAMES],    ANAMES  , /* Case   C  # tokens */
  155.      key[KNMTOKENS], ANMTOKES, /* Case   D  # tokens */
  156.      key[KNUMBERS],  ANUMBERS, /* Case   E  # tokens */
  157.      key[KNUTOKENS], ANUTOKES, /* Case   F  # tokens */
  158.      NULL,           0         /* Case   0  ERROR    */
  159. };
  160. struct map enttab[] = {       /* Entity declaration second parameter. */
  161.      key[KCDATA],     ESC ,
  162.      key[KSDATA],     ESX ,
  163.      key[KMS],        ESMS,
  164.      key[KPI],        ESI ,
  165.      key[KSTARTTAG],  ESS ,
  166.      key[KENDTAG],    ESE ,
  167.      key[KMD],        ESMD,
  168.      NULL,            0
  169. };
  170. struct map exttab[] = {       /* Keywords for external identifier. */
  171.      key[KSYSTEM],    EDSYSTEM,
  172.      key[KPUBLIC],    EDPUBLIC,
  173.      NULL,            0
  174. };
  175. struct map extettab[] = {       /* Keywords for external entity type. */
  176.      key[KCDATA],     ESNCDATA,
  177.      key[KNDATA],     ESNNDATA,
  178.      key[KSDATA],     ESNSDATA,
  179.      key[KSUBDOC],    ESNSUB,
  180.      NULL,            0
  181. };
  182. struct map funtab[] = {       /* Function character reference names. */
  183.      key[KRE],       RECHAR,
  184.      key[KRS],       RSCHAR,
  185.      key[KSPACE],    SPCCHAR,
  186.      (UNCH *)"TAB",  TABCHAR, /* We should use an extra table for added functions. */
  187.      NULL,           0
  188. };
  189. struct map mstab[] = {        /* Marked section keywords. */
  190.      key[KTEMP],    MSTEMP  ,
  191.      key[KINCLUDE], MSTEMP  , /* Treat INCLUDE like TEMP; both are NOPs.*/
  192.      key[KRCDATA],  MSRCDATA,
  193.      key[KCDATA],   MSCDATA ,
  194.      key[KIGNORE],  MSIGNORE,
  195.      NULL,          0
  196. };
  197. struct map pubcltab[] = {     /* Names for public text class. */
  198.      (UNCH *)"CAPACITY",  FPICAP  ,
  199.      (UNCH *)"CHARSET",   FPICHARS,
  200.      (UNCH *)"DOCUMENT",  FPIDOC  ,
  201.      (UNCH *)"DTD",       FPIDTD  ,
  202.      (UNCH *)"ELEMENTS",  FPIELEM ,
  203.      (UNCH *)"ENTITIES",  FPIENT  ,
  204.      (UNCH *)"LPD",       FPILPD  ,
  205.      (UNCH *)"NONSGML",   FPINON  ,
  206.      (UNCH *)"NOTATION",  FPINOT  ,
  207.      (UNCH *)"SHORTREF",  FPISHORT,
  208.      (UNCH *)"SUBDOC",    FPISUB  ,
  209.      (UNCH *)"SYNTAX",    FPISYN  ,
  210.      (UNCH *)"TEXT",      FPITEXT ,
  211.      NULL,            0
  212. };
  213. UNCH indefent[] = "\12#DEFAULT";   /* Internal name: default entity name. */
  214. UNCH indefetd[] = "\12*DOCTYPE";   /* Internal name: default document type. */
  215. UNCH indocent[] = "\12*SGMLDOC";   /* Internal name: SGML document entity. */
  216. UNCH indocetd[]  = "\6*DOC";       /* Internal name: document level etd. */
  217. UNCH indtdent[]  = "\11*DTDENT";   /* Internal name: external DTD entity. */
  218.  
  219. struct etd dumetd[3];
  220. struct entity *dumpecb;
  221. UNCH sgmlkey[] = "SGML";
  222.